#pragma once

#include "IXUIThreadProc.h"
#include "XBaseObjImpl.h"
#include <queue>
#include <XLock.h>

typedef struct
{
    UIProcFunc Func;
    LPARAM lParam;
} stUIProcInfo;
typedef std::queue<stUIProcInfo> UIProcQueue;

class CXUIThreadProcImpl : public CXBaseObjImpl<IXUIThreadProc>
{
    typedef CXBaseObjImpl<IXUIThreadProc> superclass;
    DEF_SKIN_CLASS_SINGLE_INTF(CXUIThreadProcImpl,
        superclass,
        gs_strGuidXSkin,
        IXUIThreadProc,
        eIntf_Singleton);

public:
    CXUIThreadProcImpl();
    virtual ~CXUIThreadProcImpl();

public:
    // IXUIThreadProc
    virtual HRESULT STDMETHODCALLTYPE PostUIThreadProc(UIProcFunc func, LPARAM lParam);
    virtual HRESULT STDMETHODCALLTYPE SendUIThreadProc(UIProcFunc func, LPARAM lParam);

public:
    // IXBaseObj
    virtual void    STDMETHODCALLTYPE OnFinalRelease();

protected:
    // CXUIThreadProcImpl
    void        ReleaseData();
    BOOL        NeedSyncWnd();
    void        DestroySyncWnd();

    static LRESULT CALLBACK SyncWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

protected:
    XWND            m_xSyncWnd;
    UINT            m_nUIThreadAddTaskMsgId;
};

